local Msg = require("core.Msg")
local OperateActivityExcel = require("excel.OperateActivity")
local Grid = require("bag.Grid")
local ActDefine = require("activity.Define")
local BagLogic = require("bag.BagLogic")
local Broadcast = require("broadcast.Broadcast")
local Lang = require("common.Lang")
local OperateActFL = require("activity.OperateActFL")
local HtmlUtil = require("common.HtmlUtil")
local Log = require("common.Log")
local BountyLogic = require("task.BountyLogic")
local CopyCommon = require("copy.CopyCommon")

function getConfig(id)
  if id == ActDefine.OPERATEACT_TYPE_GOODPK then
    return OperateActivityExcel.goodPK
  elseif id == ActDefine.OPERATEACT_TYPE_BOUNTYDOUBLE then
    return OperateActivityExcel.bountyDouble
  else
    return OperateActivityExcel.duobaoDouble
  end
end

function open(human, id, type)
  local sendMsg = Msg.gc.GC_OPEN_YUNYING_ACTIVITY
  local activityNum
  if type == 2 then
    activityNum = OperateActFL.onGetTomorrowActRuleID(id)
  else
    activityNum = OperateActFL.onGetCurActRuleID(id)    
  end
  local CurConfig = getConfig(id)
  local activity = CurConfig[activityNum]
  if not activity then
    return
  end
  sendMsg.info[0] = #activity.reward
  local cache = {}
  for i=1, #activity.reward do
    sendMsg.info[i].reward[0] = 1    
    Grid.create(cache, activity.reward[i][1], activity.reward[i][2])
    Grid.makeItem(cache, sendMsg.info[i].reward[1], 0, human)    
    sendMsg.info[i].args[0] = 1
    sendMsg.info[i].args[1] = activity.isDouble[i]
    sendMsg.info[i].canGet = 0
    sendMsg.info[i].name = ""
  end
  sendMsg.myInfo[0] = 3
  sendMsg.myInfo[1] = human.db.offlinePkRank
  if id == ActDefine.OPERATEACT_TYPE_BOUNTYDOUBLE then
    sendMsg.myInfo[2] = BountyLogic.getCnt(human) or 0
    sendMsg.myInfo[3] = BountyLogic.getMaxCnt(human) or 0
  elseif id == ActDefine.OPERATEACT_TYPE_DUOBAODOUBLE then
    sendMsg.myInfo[2] = CopyCommon.getCopyEnterCount(human, 9009) or 0
    sendMsg.myInfo[3] = CopyCommon.getCopyMaxEnterCount(human, 9009) or 0
  else
    sendMsg.myInfo[2] = 0
    sendMsg.myInfo[3] = 0
  end
  sendMsg.activityId = id 
  sendMsg.type = type or 1 
  Msg.send(sendMsg, human.fd)
end
